/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package at.alexanderpehm.greenleaves.impl;

import at.alexanderpehm.greenleaves.Event;
import at.alexanderpehm.greenleaves.GenderType;
import at.alexanderpehm.greenleaves.GreenleavesPackage;
import at.alexanderpehm.greenleaves.Media;
import at.alexanderpehm.greenleaves.Note;
import at.alexanderpehm.greenleaves.Person;
import at.alexanderpehm.greenleaves.Source;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectResolvingEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Person</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link at.alexanderpehm.greenleaves.impl.PersonImpl#getFirstName <em>First Name</em>}</li>
 *   <li>{@link at.alexanderpehm.greenleaves.impl.PersonImpl#getGender <em>Gender</em>}</li>
 *   <li>{@link at.alexanderpehm.greenleaves.impl.PersonImpl#getId <em>Id</em>}</li>
 *   <li>{@link at.alexanderpehm.greenleaves.impl.PersonImpl#getLastName <em>Last Name</em>}</li>
 *   <li>{@link at.alexanderpehm.greenleaves.impl.PersonImpl#getMaidenName <em>Maiden Name</em>}</li>
 *   <li>{@link at.alexanderpehm.greenleaves.impl.PersonImpl#getMiddleName <em>Middle Name</em>}</li>
 *   <li>{@link at.alexanderpehm.greenleaves.impl.PersonImpl#getParents <em>Parents</em>}</li>
 *   <li>{@link at.alexanderpehm.greenleaves.impl.PersonImpl#getNotes <em>Notes</em>}</li>
 *   <li>{@link at.alexanderpehm.greenleaves.impl.PersonImpl#getMedia <em>Media</em>}</li>
 *   <li>{@link at.alexanderpehm.greenleaves.impl.PersonImpl#getSources <em>Sources</em>}</li>
 *   <li>{@link at.alexanderpehm.greenleaves.impl.PersonImpl#getEvents <em>Events</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class PersonImpl extends EObjectImpl implements Person {
	/**
	 * The default value of the '{@link #getFirstName() <em>First Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getFirstName()
	 * @generated
	 * @ordered
	 */
	protected static final String FIRST_NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getFirstName() <em>First Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getFirstName()
	 * @generated
	 * @ordered
	 */
	protected String firstName = FIRST_NAME_EDEFAULT;

	/**
	 * The default value of the '{@link #getGender() <em>Gender</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getGender()
	 * @generated
	 * @ordered
	 */
	protected static final GenderType GENDER_EDEFAULT = GenderType.MALE;

	/**
	 * The cached value of the '{@link #getGender() <em>Gender</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getGender()
	 * @generated
	 * @ordered
	 */
	protected GenderType gender = GENDER_EDEFAULT;

	/**
	 * This is true if the Gender attribute has been set.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 * @ordered
	 */
	protected boolean genderESet;

	/**
	 * The default value of the '{@link #getId() <em>Id</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getId()
	 * @generated
	 * @ordered
	 */
	protected static final String ID_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getId() <em>Id</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getId()
	 * @generated
	 * @ordered
	 */
	protected String id = ID_EDEFAULT;

	/**
	 * The default value of the '{@link #getLastName() <em>Last Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLastName()
	 * @generated
	 * @ordered
	 */
	protected static final String LAST_NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getLastName() <em>Last Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLastName()
	 * @generated
	 * @ordered
	 */
	protected String lastName = LAST_NAME_EDEFAULT;

	/**
	 * The default value of the '{@link #getMaidenName() <em>Maiden Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMaidenName()
	 * @generated
	 * @ordered
	 */
	protected static final String MAIDEN_NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getMaidenName() <em>Maiden Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMaidenName()
	 * @generated
	 * @ordered
	 */
	protected String maidenName = MAIDEN_NAME_EDEFAULT;

	/**
	 * The default value of the '{@link #getMiddleName() <em>Middle Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMiddleName()
	 * @generated
	 * @ordered
	 */
	protected static final String MIDDLE_NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getMiddleName() <em>Middle Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMiddleName()
	 * @generated
	 * @ordered
	 */
	protected String middleName = MIDDLE_NAME_EDEFAULT;

	/**
	 * The cached value of the '{@link #getParents() <em>Parents</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getParents()
	 * @generated
	 * @ordered
	 */
	protected EList<Person> parents;

	/**
	 * The cached value of the '{@link #getNotes() <em>Notes</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getNotes()
	 * @generated
	 * @ordered
	 */
	protected EList<Note> notes;

	/**
	 * The cached value of the '{@link #getMedia() <em>Media</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMedia()
	 * @generated
	 * @ordered
	 */
	protected EList<Media> media;

	/**
	 * The cached value of the '{@link #getSources() <em>Sources</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSources()
	 * @generated
	 * @ordered
	 */
	protected EList<Source> sources;

	/**
	 * The cached value of the '{@link #getEvents() <em>Events</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEvents()
	 * @generated
	 * @ordered
	 */
	protected EList<Event> events;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected PersonImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return GreenleavesPackage.Literals.PERSON;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getFirstName() {
		return firstName;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setFirstName(String newFirstName) {
		String oldFirstName = firstName;
		firstName = newFirstName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, GreenleavesPackage.PERSON__FIRST_NAME, oldFirstName, firstName));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public GenderType getGender() {
		return gender;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setGender(GenderType newGender) {
		GenderType oldGender = gender;
		gender = newGender == null ? GENDER_EDEFAULT : newGender;
		boolean oldGenderESet = genderESet;
		genderESet = true;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, GreenleavesPackage.PERSON__GENDER, oldGender, gender, !oldGenderESet));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void unsetGender() {
		GenderType oldGender = gender;
		boolean oldGenderESet = genderESet;
		gender = GENDER_EDEFAULT;
		genderESet = false;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.UNSET, GreenleavesPackage.PERSON__GENDER, oldGender, GENDER_EDEFAULT, oldGenderESet));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean isSetGender() {
		return genderESet;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getId() {
		return id;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setId(String newId) {
		String oldId = id;
		id = newId;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, GreenleavesPackage.PERSON__ID, oldId, id));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getLastName() {
		return lastName;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setLastName(String newLastName) {
		String oldLastName = lastName;
		lastName = newLastName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, GreenleavesPackage.PERSON__LAST_NAME, oldLastName, lastName));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getMaidenName() {
		return maidenName;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setMaidenName(String newMaidenName) {
		String oldMaidenName = maidenName;
		maidenName = newMaidenName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, GreenleavesPackage.PERSON__MAIDEN_NAME, oldMaidenName, maidenName));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getMiddleName() {
		return middleName;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setMiddleName(String newMiddleName) {
		String oldMiddleName = middleName;
		middleName = newMiddleName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, GreenleavesPackage.PERSON__MIDDLE_NAME, oldMiddleName, middleName));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Person> getParents() {
		if (parents == null) {
			parents = new EObjectResolvingEList<Person>(Person.class, this, GreenleavesPackage.PERSON__PARENTS);
		}
		return parents;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Note> getNotes() {
		if (notes == null) {
			notes = new EObjectResolvingEList<Note>(Note.class, this, GreenleavesPackage.PERSON__NOTES);
		}
		return notes;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Media> getMedia() {
		if (media == null) {
			media = new EObjectResolvingEList<Media>(Media.class, this, GreenleavesPackage.PERSON__MEDIA);
		}
		return media;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Source> getSources() {
		if (sources == null) {
			sources = new EObjectResolvingEList<Source>(Source.class, this, GreenleavesPackage.PERSON__SOURCES);
		}
		return sources;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Event> getEvents() {
		if (events == null) {
			events = new EObjectResolvingEList<Event>(Event.class, this, GreenleavesPackage.PERSON__EVENTS);
		}
		return events;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case GreenleavesPackage.PERSON__FIRST_NAME:
				return getFirstName();
			case GreenleavesPackage.PERSON__GENDER:
				return getGender();
			case GreenleavesPackage.PERSON__ID:
				return getId();
			case GreenleavesPackage.PERSON__LAST_NAME:
				return getLastName();
			case GreenleavesPackage.PERSON__MAIDEN_NAME:
				return getMaidenName();
			case GreenleavesPackage.PERSON__MIDDLE_NAME:
				return getMiddleName();
			case GreenleavesPackage.PERSON__PARENTS:
				return getParents();
			case GreenleavesPackage.PERSON__NOTES:
				return getNotes();
			case GreenleavesPackage.PERSON__MEDIA:
				return getMedia();
			case GreenleavesPackage.PERSON__SOURCES:
				return getSources();
			case GreenleavesPackage.PERSON__EVENTS:
				return getEvents();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case GreenleavesPackage.PERSON__FIRST_NAME:
				setFirstName((String)newValue);
				return;
			case GreenleavesPackage.PERSON__GENDER:
				setGender((GenderType)newValue);
				return;
			case GreenleavesPackage.PERSON__ID:
				setId((String)newValue);
				return;
			case GreenleavesPackage.PERSON__LAST_NAME:
				setLastName((String)newValue);
				return;
			case GreenleavesPackage.PERSON__MAIDEN_NAME:
				setMaidenName((String)newValue);
				return;
			case GreenleavesPackage.PERSON__MIDDLE_NAME:
				setMiddleName((String)newValue);
				return;
			case GreenleavesPackage.PERSON__PARENTS:
				getParents().clear();
				getParents().addAll((Collection<? extends Person>)newValue);
				return;
			case GreenleavesPackage.PERSON__NOTES:
				getNotes().clear();
				getNotes().addAll((Collection<? extends Note>)newValue);
				return;
			case GreenleavesPackage.PERSON__MEDIA:
				getMedia().clear();
				getMedia().addAll((Collection<? extends Media>)newValue);
				return;
			case GreenleavesPackage.PERSON__SOURCES:
				getSources().clear();
				getSources().addAll((Collection<? extends Source>)newValue);
				return;
			case GreenleavesPackage.PERSON__EVENTS:
				getEvents().clear();
				getEvents().addAll((Collection<? extends Event>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case GreenleavesPackage.PERSON__FIRST_NAME:
				setFirstName(FIRST_NAME_EDEFAULT);
				return;
			case GreenleavesPackage.PERSON__GENDER:
				unsetGender();
				return;
			case GreenleavesPackage.PERSON__ID:
				setId(ID_EDEFAULT);
				return;
			case GreenleavesPackage.PERSON__LAST_NAME:
				setLastName(LAST_NAME_EDEFAULT);
				return;
			case GreenleavesPackage.PERSON__MAIDEN_NAME:
				setMaidenName(MAIDEN_NAME_EDEFAULT);
				return;
			case GreenleavesPackage.PERSON__MIDDLE_NAME:
				setMiddleName(MIDDLE_NAME_EDEFAULT);
				return;
			case GreenleavesPackage.PERSON__PARENTS:
				getParents().clear();
				return;
			case GreenleavesPackage.PERSON__NOTES:
				getNotes().clear();
				return;
			case GreenleavesPackage.PERSON__MEDIA:
				getMedia().clear();
				return;
			case GreenleavesPackage.PERSON__SOURCES:
				getSources().clear();
				return;
			case GreenleavesPackage.PERSON__EVENTS:
				getEvents().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case GreenleavesPackage.PERSON__FIRST_NAME:
				return FIRST_NAME_EDEFAULT == null ? firstName != null : !FIRST_NAME_EDEFAULT.equals(firstName);
			case GreenleavesPackage.PERSON__GENDER:
				return isSetGender();
			case GreenleavesPackage.PERSON__ID:
				return ID_EDEFAULT == null ? id != null : !ID_EDEFAULT.equals(id);
			case GreenleavesPackage.PERSON__LAST_NAME:
				return LAST_NAME_EDEFAULT == null ? lastName != null : !LAST_NAME_EDEFAULT.equals(lastName);
			case GreenleavesPackage.PERSON__MAIDEN_NAME:
				return MAIDEN_NAME_EDEFAULT == null ? maidenName != null : !MAIDEN_NAME_EDEFAULT.equals(maidenName);
			case GreenleavesPackage.PERSON__MIDDLE_NAME:
				return MIDDLE_NAME_EDEFAULT == null ? middleName != null : !MIDDLE_NAME_EDEFAULT.equals(middleName);
			case GreenleavesPackage.PERSON__PARENTS:
				return parents != null && !parents.isEmpty();
			case GreenleavesPackage.PERSON__NOTES:
				return notes != null && !notes.isEmpty();
			case GreenleavesPackage.PERSON__MEDIA:
				return media != null && !media.isEmpty();
			case GreenleavesPackage.PERSON__SOURCES:
				return sources != null && !sources.isEmpty();
			case GreenleavesPackage.PERSON__EVENTS:
				return events != null && !events.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (firstName: ");
		result.append(firstName);
		result.append(", gender: ");
		if (genderESet) result.append(gender); else result.append("<unset>");
		result.append(", id: ");
		result.append(id);
		result.append(", lastName: ");
		result.append(lastName);
		result.append(", maidenName: ");
		result.append(maidenName);
		result.append(", middleName: ");
		result.append(middleName);
		result.append(')');
		return result.toString();
	}

} //PersonImpl
